package com.lb.uts.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lb.uts.entity.JobExecuteRecord;
import com.lb.uts.entity.JobSearch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 任务执行记录 Mapper 接口
 * </p>
 *
 * @author cacframe
 * @since 2019-04-26
 */
@Repository
@Mapper
public interface JobExecuteRecordMapper extends BaseMapper<JobExecuteRecord> {
    @Select("<script>select re.id,re.exe_ip,re.start_time,re.end_time,re.call_status,re.error_msg,re.response_content,re.ip,s.job_name as jobId from job_execute_record re \n" +
            "JOIN schedule_job s on re.job_id = s.job_id" +
            "<if test='status!=null'>  and call_status = #{status}</if> " +
            "<if test='jobSearch.jobName!=null'>  and s.job_name = #{jobSearch.jobName}</if> " +
            "order by re.start_time desc</script>")
    List<JobExecuteRecord> queryByStatus(@Param("status") String status, @Param("jobSearch") JobSearch jobSearch);

    @Select("<script>select count(1) from job_execute_record where job_id = #{jobId} <if test='status!=null'>and call_status = #{status}</if></script>")
    int countJobRecordNum(@Param("jonId")String jobId,@Param("status")String status);
}
